<template>

    <m-table name="admin-order/order-by-state/2" :action="action" :search="search" :params="params" ref="table">

        <el-table-column label="下单人" prop="clientName" width="140" />

        <el-table-column label="手机号" prop="clientPhone"  width="140" />

        <el-table-column label="所属商户" prop="storeName"  width="140" />

        <el-table-column label="订单金额" prop="orderPrice"  width="140" />

        <el-table-column label="实际付款" prop="payPrice"  width="140" />

        <el-table-column label="优惠金额" prop="couponPrice"  width="140" />

        <el-table-column label="收货地址"  width="220">
            <template slot-scope="scope">
                {{scope.row.address.province}}{{scope.row.address.city}}{{scope.row.address.region}}
                <br>
                {{scope.row.address.detail}}
            </template>
        </el-table-column>

        <el-table-column label="商品信息"  width="220">
            <template slot-scope="scope">
                <el-tag type="danger" v-for="(item,index) in scope.row.goods" :key="index" style="margin: 0  10px 10px 0">
                    {{item.goodsName}} x {{item.number}}
                </el-tag>
            </template>
        </el-table-column>

        <el-table-column label="订单状态"  width="140">
            <template slot-scope="scope">
                {{getOrderState(scope.row.orderState)}}
            </template>
        </el-table-column>

        <el-table-column label="订单备注" prop="memo"  width="140" />

        <el-table-column label="订单审核时间" prop="orderValidTime"  width="220" />

        <el-table-column label="出库审核时间" prop="outStockValidTime"  width="220" />

        <el-table-column label="付款时间" prop="payTime"  width="220" />

        <el-table-column label="到货时间" prop="expectTime"  width="220" />

        <el-table-column label="下单时间" prop="created" width="220" />

        <el-table-column label="操作" width="100" fixed="right">
            <el-button slot-scope="scope" type="success" size="mini" @click="send(scope.row)">发货</el-button>
        </el-table-column>
    </m-table>

  

</template>

<script>
import request from '@/utils/request'
import { orderState  } from '@/config/account'
export default {
    data() {
        return {
            orderState:orderState,
            search: [
                { icon: 'el-icon-mobile', type: 'like', name: 'y.name', label: '用户姓名', span: 4, value: '' },
                { icon: 'el-icon-mobile', type: 'like', name: 'y.phone', label: '联系方式', span: 4, value: '' },
                { icon: 'el-icon-mobile', type: 'like', name: 'z.name', label: '商户名称', span: 4, value: '' }

            ],
            action: { remove: false, edit: false, add: false, export: false },
            params:[
                { name: 'id', value: '', hide: true },
                { name: 'name', value: '', label: '姓名' , type:'string'},
                { name: 'phone', value: '', label: '手机号' , type:'string'},
                { name: 'pwd', value: '', label: '登录密码' , type:'string'},
                { name: 'storeId', value: '', label: '所属商户' , type:'apiSelect' , url:'admin-store/name' },
            ]
        }
    },
    methods:{
       getOrderState(e){
            return this.orderState.find(x=> x.id == e).name || '未知'
       },
       async send(e){
           const res = await request.post(`admin-order/send-order/${e.id}`)
           this.$refs.table.reload()
       }
    }
}
</script>